home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
dskut
/
record11.zip
/
RECORD11.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-07-31
|
23KB
|
795 lines
Page 60,132
;----------------------------------------------------------------------
; RECORDER.ASM - A resident program which counts file operations.
; Run it once to install and initialize it. Run it again later to
; view a list of files which have been accessed. The table
; shows how many disk accesses have been made while reading and
; writing to the file.
;
; SYNTAX: RECORDER [n] [/R]
; USE n to specify the maximum number of files (default=200)
; Use /R to reset the file table.
;Toad Hall Tweak, Jul 88
; - tightened code a little
; - no functional changes
;David Kirschbaum
;Toad Hall
;kirsch@braggvax.ARPA
;----------------------------------------------------------------------
CSEG SEGMENT para public 'CODE'
ASSUME CS:CSEG,DS:CSEG, ES:CSEG
ORG 100H ;Beginning for .COM programs
Start proc near
JMP Initialize ;Initialization code is at end
;-----------------------------------------------------------------------
; Data area used by this program
;-----------------------------------------------------------------------
COPYRIGHT DB 'RECORDER 1.1',0DH,0AH,'$'
; db ' (c) 1988 Ziff Communications Co.'
;PROGRAMMER DB 13,10,'PC Magazine ',254,' Tom Kihlken$',1AH
full_mess DB '*Table is saturated*$'
oldint21 DD ? ;Old DOS function interrupt vector
oldint13 DD ? ;Old BIOS disk I/O interrupt vector
num_files DW 200 ;Default size of the table
file_table_end DW ?
last_file DW ?
last_handle DW ?
current_file DB 11 DUP (?)
current_handle DW ?
function_id DW ?
busy_flag DB 0
bios_IO_count DW 0 ;Counts disk accesses made by BIOS
HANDLE_TABLE EQU OFFSET header ;TH was Initialize
FILE_TABLE EQU HANDLE_TABLE + NUM_HANDLES * 4
NUM_HANDLES EQU 30
ENTRY_SIZE EQU 20
Start endp
;-----------------------------------------------------------------------
; Interrupt 13 (Diskette I/O) This routine counts disk sector accesses.
;-----------------------------------------------------------------------
NewInt13 PROC FAR
ASSUME DS:NOTHING, ES:NOTHING
CMP AH,2 ;Is function lower than 2?
JB Dont_Count ;If yes, then ignore it
CMP AH,4 ;Is function higher than 4?
JA Dont_Count ;If yes, then ignore it
INC CS:bios_IO_count ;Add sectors count to total
Dont_Count:
JMP CS:oldint13 ;Continue with disk interrupt
NewInt13 ENDP
;-----------------------------------------------------------------------
; Interrupt 21 (DOS functions) This routine counts file accesses.
;-----------------------------------------------------------------------
NewInt21 PROC FAR
ASSUME DS:NOTHING, ES:NOTHING
PUSHF ;Save callers flags
STI ;Get interrupts back on
CMP CS:busy_flag,0 ;Are we busy now?
JNE Old_Dos ;If busy, just pass it to DOS
CMP AH,4BH ;Is it the EXEC function?
JE Exec ;Handle EXEC specially
CMP AH,0EH ;Is it below 0EH?
JBE Old_Dos ;If yes, ignore it
CMP AH,31H ;Is it TSR function?
JE Old_Dos ;Dont intercept this call
CMP AH,45H ;Is it above 45H?
JB Intercept_It ;If yes, then ignore it
Old_Dos:
POPF ;Recover callers flags
CLI
JMP CS:oldint21 ;Allow interrupt to proceed
Exec:
PUSH AX ;Save these registers
PUSH BX
PUSH CX
PUSH SI
PUSH DI
PUSH DS
PUSH ES
MOV CS:busy_flag,1 ;Set the busy flag
MOV SI,OFFSET Parse_String ;Point to parse routine
CALL Enter_Filename ;Search file table for the file
JC Exec_Continue
INC WORD PTR [SI+12] ;TH
INC WORD PTR [SI+12] ;TH
Exec_Continue:
MOV CS:busy_flag,0 ;Not busy any more
POP ES ;Restore the registers
POP DS
POP DI
POP SI
POP CX
POP BX
POP AX
JMP Old_Dos
Intercept_It:
MOV busy_flag,1 ;Ignore any other calls
MOV function_id,AX ;Save the function ident.,
MOV bios_IO_count,0
CLI
CALL CS:oldint21 ;Do the DOS function
STI ;Reenable interrupts
PUSHF ;Save DOS result flags
PUSH AX ;Save these registers
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH DS
PUSH ES
JNC Check_Function ;If no error, continue
JMP Pop_Ret ;Otherwise just return
Check_Function:
MOV CX,function_id
SUB CH,0FH ;Is it 0Fh?
JZ Read_FCB
DEC CH ;Is it 10h?
JZ Write_FCB
SUB CH,4 ;Is it 14h?
JZ Read_FCB
DEC CH ;Is it 15h?
JZ Write_FCB
DEC CH ;Is it 16h?
JZ Read_FCB
SUB CH,0BH ;Is it 21h?
JZ Read_FCB
DEC CH ;Is it 22h?
JZ Write_FCB
DEC CH ;Is it 23h?
JZ Read_FCB
SUB CH,4 ;Is it 27h?
JZ Read_FCB
DEC CH ;Is it 28h?
JZ Write_FCB
JMP SHORT Not_FCB_Functn
Read_FCB:
MOV BX,14 ;Index for the read column
JMP SHORT Inc_FCB_Count
Write_FCB:
MOV BX,16 ;Index for the write column
Inc_FCB_Count:
MOV SI,OFFSET Parse_FCB
CALL Enter_Filename ;Search file table for the file
JC Jump_Pop_Ret ;Quit if file not in table
MOV AX,bios_IO_count ;This many disk operations made
ADD CS:[SI][BX],AX ;Add it to the indexed column
ADD CS:[SI+12],AX ;Add it to the total
JMP Pop_Ret
; If it was not a FCB function, see if it was handle I/O
Not_FCB_Functn:
SUB CH,14H ;Is it 3Ch?
JE New_Handle
DEC CH ;Is it 3Dh?
JE New_Handle
DEC CH ;Is it 3Eh?
JE Write_Handle
DEC CH ;Is it 3Fh?
JE Read_Handle
DEC CH ;Is it 40h?
JE Write_Handle
SUB CH,2 ;Is it 42h?
JE Read_Handle
SUB CH,2 ;Is it 44h?
JE IO_Control
JMP Pop_Ret
New_Handle:
CMP AX,5 ;Is it a standard handle?
JGE Good_Handle ;If not, then record it
Jump_Pop_Ret:
JMP Pop_Ret ;Jump to the return
Read_Handle:
MOV CX,14 ;Index for the read column
JMP SHORT Inc_Dev_Count
IO_Control:
CMP CL,2 ;Is it a read request?
JE Read_Handle ;Treat it as a read
CMP CL,3 ;Is it a write request?
JNE Jump_Pop_Ret ;If not read or write, ignore it
Write_Handle:
MOV CX,16 ;Index for the write column
Inc_Dev_Count:
CMP BX,5 ;Is it a standard handle?
JB Jump_Pop_Ret ;If it is, then ignore it
PUSH CX ;Put index on the stack
; Now search the handle table for the handle in BX.
CALL Add_PSP ;Add in the current PSP segment
MOV DI,HANDLE_TABLE ;Point to the handle table
MOV CX,NUM_HANDLES ;Search the entire table
Handle_Loop:
CMP BX,CS:[DI] ;Is it a match?
JE Handle_Match ;If it is, we've found it
ADD DI,4 ;If not, look at next entry
LOOP Handle_Loop
POP BX ;Restore the stack
JMP SHORT Pop_Ret ;Return if handle was not found
; If the handle is being closed, then the entry is deleted.
Handle_Match:
CMP BYTE PTR function_id+1,3EH ;Closing this file?
JNE Not_Close
MOV WORD PTR CS:[DI],0
Not_Close:
MOV DI,CS:[DI+2] ;Get pointer to file table entry
POP BX ;Get the index back
MOV AX,bios_IO_count ;Get the sector count
ADD CS:[DI][BX],AX ;Add it to selected column
ADD CS:[DI+12],AX ;And also to the total column
JMP SHORT Pop_Ret
Good_Handle:
MOV current_handle,AX ;Save the handle
MOV SI,OFFSET Parse_String ;Point to parse routine
CALL Enter_Filename ;Add the file to the table
JC Jump_Pop_Ret ;If table is full, return
MOV AX,bios_IO_count ;Get number of sectors
add [SI+12],ax ;TH Add to the total column
add [SI+14],ax ;TH Add to the read column
; Now enter this new handle to the handle table
MOV DI,last_handle ;Get location of last entry
ADD DI,4 ;Advance it one position
CMP DI,HANDLE_TABLE+NUM_HANDLES*4
JNE Keep_Going
MOV DI,HANDLE_TABLE
Keep_Going:
MOV last_handle,DI ;Now this is the last handle
MOV BX,current_handle ;Get handle back
CALL Add_PSP ;Add in the current PSP segment
MOV CS:[DI],BX ;Store the handle
MOV CS:[DI+2],SI ;Store location in file table
Pop_Ret:
MOV CS:busy_flag,0 ;Not busy any more
POP ES ;Restore all registers
POP DS
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
POPF ;Recover DOS result flags
STI ;Return with interrupts on
RET 2 ;Return with these flags
NewInt21 ENDP
;-----------------------------------------------------------------------
; Enter_Filename adds the file at DS:DX to the table.
; It returns with DS:SI pointing to the entry. If CF=1, then the name
; was not in the table and no more entries could be added.
;----------------------------------------------------------------------